package com.zhan.easyexcelorder.model;


import com.alibaba.fastjson.annotation.JSONField;
import com.zhan.jpa.model.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.List;

@Entity
@Table(name = "sys_menu")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "entityCache")
@Getter
@Setter
public class SysMenu extends BaseEntity implements java.io.Serializable {
    private static final long serialVersionUID = 436177582631250154L;

    @ApiModelProperty("菜单名称")
    private String menuName;
    @ApiModelProperty("菜单地址")
    private String menuUrl;
    @ApiModelProperty("操作编码")
    private String operationCode;
    @ApiModelProperty(value = "菜单方法", allowableValues = "GET,POST,PUT,DELETE")
    private String menuMethod;
    @ApiModelProperty("菜单图标")
    private String menuIcon;
    @ApiModelProperty("手机菜单图标")
    private String phoneMenuIcon;
    @ApiModelProperty(value = "菜单类型", allowableValues = "MENU,BUTTON")
    private String menuType;
    @ApiModelProperty("菜单等级")
    private Integer menuLevel;
    @ApiModelProperty("菜单描述")
    private String menuDescription;
    @ApiModelProperty("排序字段")
    private Integer sortCount;
    @ApiModelProperty(value = "状态（0-有效，1-无效）", allowableValues = "0,1", hidden = true)
    private Integer state = 0;
    @ApiModelProperty("显示状态（0-web，1-phone，2-wen and phone）")
    private Integer viewType;

    /**
     * @Transient 表示该属性并非一个到数据库表的字段的映射, ORM框架将忽略该属性. 
     * 如果一个属性并非数据库表的字段映射,就务必将其标示为@Transient,
     * 否则,ORM框架默认其注解为@Basic
     */
    @Transient
    private Boolean checked = false;

    @JSONField(serialize = false)
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "parent_id")
    private SysMenu parent;

    /**
     * 指定了OneToMany的关联关系，mappedBy同样指定由parent来进行维护关联关系
     */
    @OneToMany(fetch = FetchType.EAGER, mappedBy = "parent")
    @Where(clause = "is_delete=0")
    @OrderBy("sortCount asc")
    private List<SysMenu> children;

}
